load("@bazel_skylib//lib:selects.bzl", "selects")
load("//bazel:mongo_src_rules.bzl", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

# TODO BUILD-16566
# This warning cause false positives with the v4 toolchain gcc on Ubuntu 2022
# ARM64 platforms, in short term we will disable the warning until we can figure
# out what the underlying issue is. Once the toolchain is updated, the
# workaround below should be removed.
selects.config_setting_group(
    name = "options_parser_needs_no_missing_indentation_flag",
    match_all = [
        "@platforms//cpu:aarch64",
        "//bazel/config:compiler_type_gcc",
    ],
)

mongo_cc_library(
    name = "options_parser",
    srcs = [
        "constraints.cpp",
        "environment.cpp",
        "option_description.cpp",
        "option_section.cpp",
        "options_parser.cpp",
        "startup_option_init.cpp",
        "startup_options.cpp",
        "value.cpp",
    ],
    copts = select({
        ":options_parser_needs_no_missing_indentation_flag": [
            "-Wno-misleading-indentation",
        ],
        "//conditions:default": [],
    }),
    tags = [
        "mongo_crypt",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/crypto:sha_block",
        "//src/mongo/util/net:http_client",
        "//src/mongo/util/net:network",
        "//src/third_party/boost:boost_filesystem",
        "//src/third_party/boost:boost_iostreams",
        "//src/third_party/boost:boost_log",
        "//src/third_party/boost:boost_program_options",
        "//src/third_party/yaml-cpp:yaml",
    ],
)

# This library contains the initializers to run option parsing. This is
# separated into its own library because some code that is shared between many
# different binaries needs to link against the options_parser library, but not
# all these binaries need to actually run the option parsing. Linking against
# this library will cause the option parsing initializer to actually be run.
mongo_cc_library(
    name = "options_parser_init",
    srcs = [
        "options_parser_init.cpp",
    ],
    deps = [
        ":options_parser",
    ],
)

mongo_cc_unit_test(
    name = "options_parser_test",
    srcs = [
        "environment_test.cpp",
        "options_parser_test.cpp",
    ],
    data = [
        "//src/mongo/util/options_parser/test_config_files:test_data",
    ],
    tags = ["mongo_unittest_first_group"],
    deps = [
        "options_parser",
        "//src/mongo/unittest",
    ],
)
